package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 巡查通知类型枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum PatrolNotificationType implements BaseEnum {
    TASK_ASSIGNED("TASK_ASSIGNED", "任务分配"),
    TASK_REMINDER("TASK_REMINDER", "任务提醒"),
    TASK_OVERDUE("TASK_OVERDUE", "任务逾期"),
    TASK_COMPLETED("TASK_COMPLETED", "任务完成"),
    TASK_CANCELLED("TASK_CANCELLED", "任务取消"),
    VIOLATION_REPORTED("VIOLATION_REPORTED", "违规上报"),
    VIOLATION_ASSIGNED("VIOLATION_ASSIGNED", "违规分配"),
    VIOLATION_RESOLVED("VIOLATION_RESOLVED", "违规处理"),
    SYSTEM_ALERT("SYSTEM_ALERT", "系统提醒"),
    DEADLINE_REMINDER("DEADLINE_REMINDER", "截止日期提醒"),
    APPROVAL_REQUIRED("APPROVAL_REQUIRED", "需要审批"),
    APPROVAL_COMPLETED("APPROVAL_COMPLETED", "审批完成"),
    GENERAL_NOTICE("GENERAL_NOTICE", "一般通知"),
    URGENT_NOTICE("URGENT_NOTICE", "紧急通知"),
    MAINTENANCE_NOTICE("MAINTENANCE_NOTICE", "维护通知"),
    POLICY_UPDATE("POLICY_UPDATE", "政策更新"),
    TRAINING_REMINDER("TRAINING_REMINDER", "培训提醒"),
    MEETING_REMINDER("MEETING_REMINDER", "会议提醒");

    private final String code;
    private final String description;

    PatrolNotificationType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据代码获取枚举值
     *
     * @param code 代码
     * @return 枚举值
     * @throws IllegalArgumentException 如果代码无效
     */
    public static PatrolNotificationType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Patrol notification type code cannot be null or empty");
        }

        for (PatrolNotificationType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown patrol notification type code: " + code);
    }

    /**
     * 根据描述获取枚举值
     *
     * @param description 描述
     * @return 枚举值，如果未找到返回null
     */
    public static PatrolNotificationType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (PatrolNotificationType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}